package com.whnk.model.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whnk.common.log.annotation.Log;
import com.whnk.common.log.enums.BusinessType;
import com.whnk.common.security.annotation.PreAuthorize;
import com.whnk.model.domain.DefTProductInfo;
import com.whnk.model.service.IDefTProductInfoService;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.common.core.utils.poi.ExcelUtil;
import com.whnk.common.core.web.page.TableDataInfo;

/**
 * 产品定义Controller
 *
 * @author whnk
 * @date 2021-10-20
 */
@RestController
@RequestMapping("/workFlow/productDefinition/")
public class DefTProductInfoController extends BaseController
{
    @Autowired
    private IDefTProductInfoService defTProductInfoService;

    /**
     * 查询产品定义列表
     */
    @PreAuthorize(hasPermi = "model:info:list")
    @GetMapping("/list")
    public TableDataInfo list(DefTProductInfo defTProductInfo)
    {
        startPage();
        List<DefTProductInfo> list = defTProductInfoService.selectDefTProductInfoList(defTProductInfo);
        return getDataTable(list);
    }

    /**
     * 导出产品定义列表
     */
    @PreAuthorize(hasPermi = "model:info:export")
    @Log(title = "导出产品定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefTProductInfo defTProductInfo) throws IOException
    {
        List<DefTProductInfo> list = defTProductInfoService.selectDefTProductInfoList(defTProductInfo);
        ExcelUtil<DefTProductInfo> util = new ExcelUtil<DefTProductInfo>(DefTProductInfo.class);
        util.exportExcel(response, list, "导出产品定义");
    }

    /**
     * 获取产品定义详细信息
     */
    @PreAuthorize(hasPermi = "model:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(defTProductInfoService.selectDefTProductInfoById(id));
    }

    /**
     * 新增产品定义
     */
    @PreAuthorize(hasPermi = "model:info:add")
    @Log(title = "新增产品定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DefTProductInfo defTProductInfo)
    {
        return toAjax(defTProductInfoService.insertDefTProductInfo(defTProductInfo));
    }

    /**
     * 修改产品定义
     */
    @PreAuthorize(hasPermi = "model:info:edit")
    @Log(title = "修改产品定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DefTProductInfo defTProductInfo)
    {
        return toAjax(defTProductInfoService.updateDefTProductInfo(defTProductInfo));
    }

    /**
     * 删除产品定义
     */
    @PreAuthorize(hasPermi = "model:info:remove")
    @Log(title = "删除产品定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(defTProductInfoService.deleteDefTProductInfoByIds(ids));
    }
}
